home *** CD-ROM | disk | FTP | other *** search
- ; (c) Frank Meijer, December 1994.
- ;
- ;--------------------------------------------------------------------
- ; These routines are used to intercept calls to AllocMem().
- ;
- ; Sample use:
- ; realAllocMem = SetFunction( ExecBase, -198, myAllocMem );
- ;
- ; This will cause "myAllocMem()" to be called instead of the
- ; real AllocMem().
- ;
- ; From there, CALLrealAllocMem() can be called to invoke the
- ; real AllocMem() routine.
- ;
- ; Notes:
- ; - myAllocMem() must be defined by the caller. It has the
- ; same argument as AllocMem() but it is a 'C' function.
- ; APTR myAllocMem( long size, long type );
- ; (D0) (D0) (D1)
- ;--------------------------------------------------------------------
- ;
- xdef _realAllocMem
- xdef _CALLmyAllocMem
- xdef _CALLrealAllocMem
- ;
- xref _myAllocMem
- ;
- ;---------------------------
- section 0,bss
- MyExecBase:
- dc.l 0 ; Used to store exec.library base address
- _realAllocMem:
- dc.l 0
- ;
- ;---------------------------
- section 1,code
- _CALLmyAllocMem:
- move.l A6,MyExecBase ; Store for use by CALLrealAllocMem
- move.l D1,-(sp) ; Put parameters on stack
- move.l D0,-(sp) ; for call to C function
- jsr _myAllocMem
- addq.l #8,sp ; Pop stack
- rts
- ;
- ;---------------------------
- section 1,code
- _CALLrealAllocMem:
- move.l 4(sp),D0 ; get parameters from stack
- move.l 8(sp),D1
- move.l A6,-(A7) ; save A6
- movea.l MyExecBase,A6 ; set A6 to exec library base, see amiga.lib
- move.l _realAllocMem,A0
- jsr (A0)
- movea.l (A7)+,A6 ; restore A6
- rts
- ;
- ;--------------------------------------------------------------------
- ; These routines are used to intercept calls to FreeMem().
- ;
- ; Sample use:
- ; realFreeMem = SetFunction( ExecBase, -210, myFreeMem );
- ;
- ; This will cause "myFreeMem()" to be called instead of the
- ; real FreeMem().
- ;
- ; From there, CALLrealFreeMem() can be called to invoke the
- ; real FreeMem() routine.
- ;
- ; Notes:
- ; - myFreeMem() must be defined by the caller. It has the
- ; same argument as FreeMem() but it is a 'C' function.
- ; void myFreeMem( APTR memaddress, long bytesize );
- ; (A1) (D0)
- ;--------------------------------------------------------------------
- ;
- xdef _realFreeMem
- xdef _CALLmyFreeMem
- xdef _CALLrealFreeMem
- ;
- xref _myFreeMem
- ;
- ;---------------------------
- section 0,bss
- _realFreeMem:
- dc.l 0
- ;
- ;---------------------------
- section 1,code
- _CALLmyFreeMem:
- move.l A6,MyExecBase ; Store for use by CALLrealFreeMem
- move.l D0,-(sp) ; Put parameters on stack
- move.l A1,-(sp) ; for call to C function
- jsr _myFreeMem
- addq.l #8,sp ; Pop stack
- rts
- ;
- ;---------------------------
- section 1,code
- _CALLrealFreeMem:
- move.l 4(sp),A1 ; get parameters from stack
- move.l 8(sp),D0
- move.l A6,-(A7) ; save A6
- movea.l MyExecBase,A6 ; set A6 to exec library base, see amiga.lib
- move.l _realFreeMem,A0
- jsr (A0)
- movea.l (A7)+,A6 ; restore A6
- rts
- ;
- end